<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-title">健康食谱系统登录</div>
      <div class="login-info">默认账号：abo / 密码：abo</div>
      <el-form ref="loginForm" :model="rulesForm">
        <el-form-item>
          <el-input
              prefix-icon="el-icon-user"
              v-model="rulesForm.username"
              placeholder="admin">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
              prefix-icon="el-icon-lock"
              v-model="rulesForm.password"
              type="password"
              placeholder="*****">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-button" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="background-decoration">
      <div class="circle circle-1"></div>
      <div class="circle circle-2"></div>
      <div class="circle circle-3"></div>
    </div>
  </div>
</template>

<script>
import menu from "@/utils/menu";

export default {
  data() {
    return {
      rulesForm: {
        username: "",
        password: "",
        role: "管理员"
      },
      tableName: "users"
    };
  },
  methods: {
    // 登录
    login() {
      if (!this.rulesForm.username) {
        this.$message.error("请输入用户名");
        return;
      }
      if (!this.rulesForm.password) {
        this.$message.error("请输入密码");
        return;
      }

      this.$http({
        url: `${this.tableName}/login?username=${this.rulesForm.username}&password=${this.rulesForm.password}`,
        method: "post"
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.$storage.set("Token", data.token);
          this.$storage.set("role", this.rulesForm.role);
          this.$storage.set("sessionTable", this.tableName);
          this.$storage.set("adminName", this.rulesForm.username);
          this.$router.replace({path: "/index/"});
        } else {
          this.$message.error(data.msg);
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.login-container {
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f0f2f5;
  overflow: hidden;
}

.login-box {
  position: relative;
  width: 400px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  padding: 30px;
  z-index: 10;
}

.login-title {
  text-align: center;
  font-size: 22px;
  color: #333;
  font-weight: 500;
  margin-bottom: 30px;
}

.login-info {
  text-align: center;
  font-size: 14px;
  color: #606266;
  margin-bottom: 20px;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-input /deep/ .el-input__inner {
  height: 46px;
  border-radius: 23px;
  background-color: #f5f7fa;
  border: none;
  padding-left: 45px;
  color: #606266;
}

.el-input /deep/ .el-input__prefix {
  left: 15px;
  color: #909399;
}

.login-button {
  width: 100%;
  height: 46px;
  border-radius: 23px;
  background-color: #409EFF;
  border: none;
  font-size: 16px;
  letter-spacing: 2px;
  transition: all 0.3s;

  &:hover {
    background-color: #66b1ff;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }
}

.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;

  .circle {
    position: absolute;
    border-radius: 50%;
    opacity: 0.6;
  }

  .circle-1 {
    width: 300px;
    height: 300px;
    background-color: rgba(64, 158, 255, 0.2);
    top: -100px;
    right: -100px;
  }

  .circle-2 {
    width: 200px;
    height: 200px;
    background-color: rgba(103, 194, 58, 0.2);
    bottom: -70px;
    left: -70px;
  }

  .circle-3 {
    width: 150px;
    height: 150px;
    background-color: rgba(245, 108, 108, 0.2);
    bottom: 100px;
    right: 100px;
  }
}

@media (max-width: 576px) {
  .login-box {
    width: 90%;
    padding: 20px;
  }
}
</style>
